<!--
Copyright (c) 2019-2026, Hossein Moein
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of Hossein Moein and/or the DataFrame nor the
  names of its contributors may be used to endorse or promote products
  derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>

<head>
<style>
body {
  background-image: linear-gradient(Azure, AliceBlue, GhostWhite, WhiteSmoke);
}
</style>
</head>

<body style="font-family: Georgia, serif">

  <font size="+3">&#8592;</font> <a href="https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html">Back to Documentations</a><BR><BR>
  
  <table border="1">

    <tr bgcolor="lightblue">
      <th>Signature</th> <th>Description</th>
    </tr>
    <tr bgcolor="Azure">
      <td bgcolor="blue"> <font color="white">
        <PRE><B>
enum class random_policy : unsigned char  {
    num_rows_with_seed = 1,  // Number of rows with specifying a seed
    num_rows_no_seed = 2,    // Number of rows with no seed specification
    frac_rows_with_seed = 3, // Fraction of rows with specifying a seed
    frac_rows_no_seed = 4,   // Fraction of rows with no seed specification
};</B></PRE> </font>
      </td>
      <td>
        Specification for calling get_[data|view]_by_rand()<BR>
        Number of rows means the n parameter is an positive integer specifying<BR>
        the number of rows to select<BR>
        Fraction of rows means the n parameter is a positive real number [0:1]<BR>
        specifying a fraction of rows to select
      </td>
    </tr>

  </table>

  <BR>

  <table border="1">

    <tr bgcolor="lightblue">
        <th>Signature</th> <th>Description</th> <th>Parameters</th>
    </tr>
    <tr bgcolor="Azure">
      <td bgcolor="blue"> <font color="white">
        <PRE><B>
template&lt;typename ... Ts&gt;
DataFrame&lt;I, H&gt;
get_data_by_rand(random_policy spec,
                 double n,
                 seed_t seed = 0) const;
        </B></PRE></font>
      </td>
      <td>
        It returns a DataFrame (including the index and data columns) containing the data from uniform random selection. random_policy determines the behavior of method.<BR>
        <B>NOTE</B>: The actual number of rows returned might be smaller than requested. That is because the random process might produce the same number more than once.<BR>
        <B>NOTE</B>: The columns in the result are not padded with NaN.
      </td>
      <td>
        <B>Ts</b>: The list of types for all columns. A type should be specified only once.<BR>
        <B>random_policy</b>: Please see random_policy in DataFrameTypes.h. It specifies how this function should proceed.<BR>
        <B>n</b>: Depending on the random policy, it is either the number of rows to sample or a fraction of rows to sample. In case of fraction, for example 0.4 means 40% of rows.<BR>
        <B>seed</b>: (unsigned int) Depending on the random policy, user could specify a seed. The same seed should always produce the same random selection.<BR>
      </td>
    </tr>

    <tr bgcolor="Azure">
      <td bgcolor="blue"> <font color="white">
        <PRE><B>
template&lt;typename ... Ts&gt;
PtrView
get_view_by_rand(random_policy spec,
                 double n,
                 seed_t seed = 0);
        </B></PRE></font>
      </td>
      <td>
        It behaves like get_data_by_rand(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.<BR>
        <B>NOTE</B>: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.<BR>
        <B>NOTE</B>: The columns in the result are not padded with NaN.<BR>
      </td>
      <td>
        <B>Ts</b>: The list of types for all columns. A type should be specified only once.<BR>
        <B>random_policy</b>: Please see random_policy in DataFrameTypes.h. It specifies how this function should proceed.<BR>
        <B>n</b>: Depending on the random policy, it is either the number of rows to sample or a fraction of rows to sample. In case of fraction, for example 0.4 means 40% of rows.<BR>
        <B>seed</b>: (unsigned int) Depending on the random policy, user could specify a seed. The same seed should always produce the same random selection.<BR>
      </td>
    </tr>

    <tr bgcolor="Azure">
      <td bgcolor="blue"> <font color="white">
        <PRE><B>
template&lt;typename ... Ts&gt;
ConstPtrView
get_view_by_rand(random_policy spec,
                 double n,
                 seed_t seed = 0) const;
        </B></PRE></font>
      </td>
      <td>
          Same as above view, but it returns a <I>const</I> view. You can not change data in const views. But if the data is changed in the original DataFrame or through another view, it is reflected in the const view.       
      </td>
      <td>
        <B>Ts</b>: The list of types for all columns. A type should be specified only once.<BR>
        <B>random_policy</b>: Please see random_policy in DataFrameTypes.h. It specifies how this function should proceed.<BR>
        <B>n</b>: Depending on the random policy, it is either the number of rows to sample or a fraction of rows to sample. In case of fraction, for example 0.4 means 40% of rows.<BR>
        <B>seed</b>: (unsigned int) Depending on the random policy, user could specify a seed. The same seed should always produce the same random selection.<BR>
      </td>
    </tr>

  </table>

<!-- HTML generated using hilite.me --><div style="background: #ffffff00; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">static</span> <span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">test_get_data_by_rand</span>()  {

    std<span style="color: #333333">::</span>cout <span style="color: #333333">&lt;&lt;</span> <span style="background-color: #fff0f0">&quot;</span><span style="color: #666666; font-weight: bold; background-color: #fff0f0">\n</span><span style="background-color: #fff0f0">Testing get_data_by_rand() ...&quot;</span> <span style="color: #333333">&lt;&lt;</span> std<span style="color: #333333">::</span>endl;

    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>  idx <span style="color: #333333">=</span>
        { <span style="color: #0000DD; font-weight: bold">123450</span>, <span style="color: #0000DD; font-weight: bold">123451</span>, <span style="color: #0000DD; font-weight: bold">123452</span>, <span style="color: #0000DD; font-weight: bold">123453</span>, <span style="color: #0000DD; font-weight: bold">123454</span>, <span style="color: #0000DD; font-weight: bold">123455</span>, <span style="color: #0000DD; font-weight: bold">123456</span>, <span style="color: #0000DD; font-weight: bold">123457</span>, <span style="color: #0000DD; font-weight: bold">123458</span>, <span style="color: #0000DD; font-weight: bold">123459</span>, <span style="color: #0000DD; font-weight: bold">123460</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d1 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">1</span>, <span style="color: #0000DD; font-weight: bold">2</span>, <span style="color: #0000DD; font-weight: bold">3</span>, <span style="color: #0000DD; font-weight: bold">4</span>, <span style="color: #0000DD; font-weight: bold">5</span>, <span style="color: #0000DD; font-weight: bold">6</span>, <span style="color: #0000DD; font-weight: bold">7</span>, <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span>, <span style="color: #0000DD; font-weight: bold">10</span>, <span style="color: #0000DD; font-weight: bold">11</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d2 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span>, <span style="color: #0000DD; font-weight: bold">10</span>, <span style="color: #0000DD; font-weight: bold">11</span>, <span style="color: #0000DD; font-weight: bold">12</span>, <span style="color: #0000DD; font-weight: bold">13</span>, <span style="color: #0000DD; font-weight: bold">14</span>, <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span>, <span style="color: #0000DD; font-weight: bold">17</span>, <span style="color: #0000DD; font-weight: bold">18</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d3 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span>, <span style="color: #0000DD; font-weight: bold">17</span>, <span style="color: #0000DD; font-weight: bold">18</span>, <span style="color: #0000DD; font-weight: bold">19</span>, <span style="color: #0000DD; font-weight: bold">20</span>, <span style="color: #0000DD; font-weight: bold">21</span>, <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span>, <span style="color: #0000DD; font-weight: bold">24</span>, <span style="color: #0000DD; font-weight: bold">25</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d4 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span>, <span style="color: #0000DD; font-weight: bold">24</span>, <span style="color: #0000DD; font-weight: bold">25</span>, <span style="color: #0000DD; font-weight: bold">26</span>, <span style="color: #0000DD; font-weight: bold">27</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> s1 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;11&quot;</span>, <span style="background-color: #fff0f0">&quot;22&quot;</span>, <span style="background-color: #fff0f0">&quot;33&quot;</span>, <span style="background-color: #fff0f0">&quot;aa&quot;</span>, <span style="background-color: #fff0f0">&quot;bb&quot;</span>, <span style="background-color: #fff0f0">&quot;cc&quot;</span>, <span style="background-color: #fff0f0">&quot;dd&quot;</span>, <span style="background-color: #fff0f0">&quot;tt&quot;</span>, <span style="background-color: #fff0f0">&quot;uu&quot;</span>, <span style="background-color: #fff0f0">&quot;ii&quot;</span>, <span style="background-color: #fff0f0">&quot;88&quot;</span> };
    MyDataFrame         df;

    df.load_data(std<span style="color: #333333">::</span>move(idx),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_1&quot;</span>, d1),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_2&quot;</span>, d2),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_3&quot;</span>, d3),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_str&quot;</span>, s1));
    df.load_column(<span style="background-color: #fff0f0">&quot;col_4&quot;</span>, std<span style="color: #333333">::</span>move(d4), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    <span style="color: #008800; font-weight: bold">auto</span>    result <span style="color: #333333">=</span>
        df.get_data_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">5</span>);
    <span style="color: #008800; font-weight: bold">auto</span>    result2 <span style="color: #333333">=</span>
        df.get_data_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>frac_rows_with_seed, <span style="color: #6600EE; font-weight: bold">0.8</span>, <span style="color: #0000DD; font-weight: bold">23</span>);

    result2.write<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>ostream, <span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(std<span style="color: #333333">::</span>cout);

    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>  idx2 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">123450</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d12 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">1</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d22 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">8</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d32 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">15</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d42 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">22</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> s12 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;11&quot;</span> };
    MyDataFrame         df2;

    df2.load_data(std<span style="color: #333333">::</span>move(idx2),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_1&quot;</span>, d12),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_2&quot;</span>, d22),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_3&quot;</span>, d32),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_str&quot;</span>, s12));
    df2.load_column(<span style="background-color: #fff0f0">&quot;col_4&quot;</span>, std<span style="color: #333333">::</span>move(d42), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    <span style="color: #008800; font-weight: bold">auto</span>    result3 <span style="color: #333333">=</span>
        df2.get_data_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">1</span>);

    result3.write<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>ostream, <span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(std<span style="color: #333333">::</span>cout);

    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>  idx3 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">123450</span>, <span style="color: #0000DD; font-weight: bold">123451</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d13 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">1</span>, <span style="color: #0000DD; font-weight: bold">2</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d23 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d33 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d43 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> s13 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;11&quot;</span>, <span style="background-color: #fff0f0">&quot;22&quot;</span> };
    MyDataFrame         df3;

    df3.load_data(std<span style="color: #333333">::</span>move(idx3),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_1&quot;</span>, d13),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_2&quot;</span>, d23),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_3&quot;</span>, d33),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_str&quot;</span>, s13));
    df3.load_column(<span style="background-color: #fff0f0">&quot;col_4&quot;</span>, std<span style="color: #333333">::</span>move(d43), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    <span style="color: #008800; font-weight: bold">auto</span>    result4 <span style="color: #333333">=</span>
        df3.get_data_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">1</span>);

    result4.write<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>ostream, <span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(std<span style="color: #333333">::</span>cout);

    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>  idx4 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">123450</span>, <span style="color: #0000DD; font-weight: bold">123451</span>, <span style="color: #0000DD; font-weight: bold">123452</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d14 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">1</span>, <span style="color: #0000DD; font-weight: bold">2</span>, <span style="color: #0000DD; font-weight: bold">3</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d24 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span>, <span style="color: #0000DD; font-weight: bold">10</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d34 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span>, <span style="color: #0000DD; font-weight: bold">17</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d44 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span>, <span style="color: #0000DD; font-weight: bold">24</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> s14 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;11&quot;</span>, <span style="background-color: #fff0f0">&quot;22&quot;</span>, <span style="background-color: #fff0f0">&quot;33&quot;</span> };
    MyDataFrame         df4;

    df4.load_data(std<span style="color: #333333">::</span>move(idx4),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_1&quot;</span>, d14),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_2&quot;</span>, d24),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_3&quot;</span>, d34),
                  std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_str&quot;</span>, s14));
    df4.load_column(<span style="background-color: #fff0f0">&quot;col_4&quot;</span>, std<span style="color: #333333">::</span>move(d44), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    <span style="color: #008800; font-weight: bold">auto</span>    result5 <span style="color: #333333">=</span>
        df4.get_data_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">1</span>);

    result5.write<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>ostream, <span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(std<span style="color: #333333">::</span>cout);
}

<span style="color: #888888">// -----------------------------------------------------------------------------</span>

<span style="color: #008800; font-weight: bold">static</span> <span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">test_get_view_by_rand</span>()  {

    std<span style="color: #333333">::</span>cout <span style="color: #333333">&lt;&lt;</span> <span style="background-color: #fff0f0">&quot;</span><span style="color: #666666; font-weight: bold; background-color: #fff0f0">\n</span><span style="background-color: #fff0f0">Testing get_view_by_rand() ...&quot;</span> <span style="color: #333333">&lt;&lt;</span> std<span style="color: #333333">::</span>endl;

    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>  idx <span style="color: #333333">=</span>
        { <span style="color: #0000DD; font-weight: bold">123450</span>, <span style="color: #0000DD; font-weight: bold">123451</span>, <span style="color: #0000DD; font-weight: bold">123452</span>, <span style="color: #0000DD; font-weight: bold">123453</span>, <span style="color: #0000DD; font-weight: bold">123454</span>, <span style="color: #0000DD; font-weight: bold">123455</span>, <span style="color: #0000DD; font-weight: bold">123456</span>, <span style="color: #0000DD; font-weight: bold">123457</span>, <span style="color: #0000DD; font-weight: bold">123458</span>, <span style="color: #0000DD; font-weight: bold">123459</span>, <span style="color: #0000DD; font-weight: bold">123460</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d1 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">1</span>, <span style="color: #0000DD; font-weight: bold">2</span>, <span style="color: #0000DD; font-weight: bold">3</span>, <span style="color: #0000DD; font-weight: bold">4</span>, <span style="color: #0000DD; font-weight: bold">5</span>, <span style="color: #0000DD; font-weight: bold">6</span>, <span style="color: #0000DD; font-weight: bold">7</span>, <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span>, <span style="color: #0000DD; font-weight: bold">10</span>, <span style="color: #0000DD; font-weight: bold">11</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d2 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">8</span>, <span style="color: #0000DD; font-weight: bold">9</span>, <span style="color: #0000DD; font-weight: bold">10</span>, <span style="color: #0000DD; font-weight: bold">11</span>, <span style="color: #0000DD; font-weight: bold">12</span>, <span style="color: #0000DD; font-weight: bold">13</span>, <span style="color: #0000DD; font-weight: bold">14</span>, <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span>, <span style="color: #0000DD; font-weight: bold">17</span>, <span style="color: #0000DD; font-weight: bold">18</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d3 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">15</span>, <span style="color: #0000DD; font-weight: bold">16</span>, <span style="color: #0000DD; font-weight: bold">17</span>, <span style="color: #0000DD; font-weight: bold">18</span>, <span style="color: #0000DD; font-weight: bold">19</span>, <span style="color: #0000DD; font-weight: bold">20</span>, <span style="color: #0000DD; font-weight: bold">21</span>, <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span>, <span style="color: #0000DD; font-weight: bold">24</span>, <span style="color: #0000DD; font-weight: bold">25</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span> d4 <span style="color: #333333">=</span> { <span style="color: #0000DD; font-weight: bold">22</span>, <span style="color: #0000DD; font-weight: bold">23</span>, <span style="color: #0000DD; font-weight: bold">24</span>, <span style="color: #0000DD; font-weight: bold">25</span>, <span style="color: #0000DD; font-weight: bold">26</span>, <span style="color: #0000DD; font-weight: bold">27</span> };
    std<span style="color: #333333">::</span>vector<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> s1 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;11&quot;</span>, <span style="background-color: #fff0f0">&quot;22&quot;</span>, <span style="background-color: #fff0f0">&quot;33&quot;</span>, <span style="background-color: #fff0f0">&quot;aa&quot;</span>, <span style="background-color: #fff0f0">&quot;bb&quot;</span>, <span style="background-color: #fff0f0">&quot;cc&quot;</span>, <span style="background-color: #fff0f0">&quot;dd&quot;</span>, <span style="background-color: #fff0f0">&quot;tt&quot;</span>, <span style="background-color: #fff0f0">&quot;uu&quot;</span>, <span style="background-color: #fff0f0">&quot;ii&quot;</span>, <span style="background-color: #fff0f0">&quot;88&quot;</span> };
    MyDataFrame         df;

    df.load_data(std<span style="color: #333333">::</span>move(idx),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_1&quot;</span>, d1),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_2&quot;</span>, d2),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_3&quot;</span>, d3),
                 std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;col_str&quot;</span>, s1));
    df.load_column(<span style="background-color: #fff0f0">&quot;col_4&quot;</span>, std<span style="color: #333333">::</span>move(d4), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    <span style="color: #008800; font-weight: bold">const</span> MyDataFrame   <span style="color: #333333">&amp;</span>const_df <span style="color: #333333">=</span> df;
    <span style="color: #008800; font-weight: bold">auto</span>    result <span style="color: #333333">=</span>
        df.get_view_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">5</span>);
    <span style="color: #008800; font-weight: bold">auto</span>    result2 <span style="color: #333333">=</span>
        df.get_view_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>frac_rows_with_seed, <span style="color: #6600EE; font-weight: bold">0.8</span>, <span style="color: #0000DD; font-weight: bold">23</span>);
    <span style="color: #008800; font-weight: bold">auto</span>    const_result <span style="color: #333333">=</span>
        const_df.get_view_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>num_rows_no_seed, <span style="color: #0000DD; font-weight: bold">5</span>);
    <span style="color: #008800; font-weight: bold">auto</span>    const_result2 <span style="color: #333333">=</span>
        const_df.get_view_by_rand<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(random_policy<span style="color: #333333">::</span>frac_rows_with_seed, <span style="color: #6600EE; font-weight: bold">0.8</span>, <span style="color: #0000DD; font-weight: bold">23</span>);

    result2.write<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>ostream, <span style="color: #333399; font-weight: bold">double</span>, std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(std<span style="color: #333333">::</span>cout);
}
</pre></div>

  <BR><img src="https://github.com/hosseinmoein/DataFrame/blob/master/docs/LionLookingUp.jpg?raw=true" alt="C++ DataFrame"
       width="200" height="200" style="float:right"/>

</body>
</html>

<!--
Local Variables:
mode:HTML
tab-width:4
c-basic-offset:4
End:
-->
